<template>
  <div v-if="show">
    <slot></slot>
  </div>
</template>

<script>
  import { mapState, mapGetters } from 'vuex'
  export default {
    name: 'FileNameOperation',
    props: {
      check: {
        type: String,
        default: '',
        required: true,
      },
      index: {
        type: Array,
        default: () => [0],
        required: true,
      },
    },
    data() {
      return {
        show: false,
      }
    },
    watch: {
      fileNamePermissionList(val) {
        const check = this.check
        const arr = val.filter(v => v.name === check)
        // 编辑许可
        let editDisabled = false
        if (arr.length > 0) {
          let allow = arr[0].allow
          switch (allow) {
            case 0: // 0不可见
              editDisabled = true
              this.show = false
              break
            case 1: // 1只读
              editDisabled = true
              this.show = true
              break
            case 2: // 1只读
              editDisabled = false
              this.show = true
              break
            default:
              editDisabled = true
              this.show = false
              break
          }
        } else {
          this.show = false
          this.editDisabled = false
        }
        for (let i = 0; i < this.index.length; i++) {
          const item = this.index[i]
          this.$slots.default[+item - 1].componentOptions.propsData.disabled = editDisabled
        }
      },
    },
    computed: {
      ...mapState({
        fileNamePermissionList: state => state.SysPermission.fileNamePermissionList,
      }),
    },
    mounted() {},
    methods: {},
  }
</script>
